<?php
/**
 * 生成bootstrap radio checkbox
 * @author dingwu
 */
namespace App\Support;

use Frado\Helper\Arr;
use Frado\Helper\Html;

class BootstrapHtml {

    public static function radios($name, $select = null, $items = [], $option = [])
    {
        $itemCallBack = function ($index, $label, $name, $checked, $value) use ($option) {
            $itemOptions = array_merge([
                'id' => 'radio_' . Html::quoteAttrName($name) . $index,
                'value' => $value,
                'class' => 'custom-control-input',
            ], Arr::pull($option, 'itemOptions', []));
            $content = Html::radio($name, $checked, $itemOptions);

            $labelOptions = Arr::pull($option, 'labelOptions', []);
            $content .= Html::label($label, $itemOptions['id'], array_merge([
                'class' => 'custom-control-label',
            ], $labelOptions));

            return Html::tag('div', $content, array_merge([
                'class' => 'custom-control custom-radio custom-control-inline',
            ], $option));
        };

        $option['item'] = $itemCallBack;

        return Html::radioList($name, $select, $items, $option);
    }

    public static function checkboxs($name, $select, $items, $option = [])
    {
        $itemCallBack = function ($index, $label, $name, $checked, $value) use ($option) {
            $itemOptions = array_merge([
                'id' => 'checkbox_' . Html::quoteAttrName($name) . $index,
                'value' => $value,
                'class' => 'custom-control-input',
            ], Arr::pull($option, 'itemOptions', []));
            $content = Html::checkbox($name, $checked, $itemOptions);

            $labelOptions = Arr::pull($option, 'labelOptions', []);
            $content .= Html::label($label, $itemOptions['id'], array_merge([
                'class' => 'custom-control-label',
            ], $labelOptions));

            return Html::tag('div', $content, array_merge([
                'class' => 'custom-control custom-checkbox custom-control-inline',
            ], $option));
        };

        $option['item'] = $itemCallBack;

        return Html::checkboxList($name, $select, $items, $option);
    }

	public static function labelstat($item, $content, $title = '', $option = []) {
        return Html::tag('span', $content, array_merge([
            'class' => "label label-{$item}",
            'title' => $title
        ], $option));
    }

}
